2015-08-15.sql 5.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. 
  2. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_OrdersWageDigital')
  3. BEGIN
  4. DROP VIEW [dbo].Vw_OrdersWageDigital
  5. END
  6. GO
  7. create View Vw_OrdersWageDigital
  8. as
  9. select
  10. tb_ErpOrderDigital.Id
  11. , Ordv_Number
  12. ,Ordv_ViceNumber
  13. ,Ordv_DigitalNumber
  14. ,Ord_Number
  15. ,Ord_Type
  16. ,Ord_Class
  17. ,Ord_PhotographyCategory
  18. ,Ord_SeriesName
  19. ,Ord_SeriesPrice
  20. ,(case when Ord_Type = '1' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) else (select top 1 Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_Number = Ord_Number) end) as 拍摄名称
  21. ,(select Cus_Name from tempTB_AggregationCustomer where Ord_Number=GP_OrderNumber) as 客户名称
  22. ,(select Cus_Telephone from tempTB_AggregationCustomer where Ord_Number=GP_OrderNumber) as 客户电话
  23. ,Ordv_ClothingName as 礼服师ID
  24. ,dbo.fn_CheckUserIDGetUserName(Ordv_ClothingName) as 礼服师
  25. ,Ordv_ClothingStatus as 礼服师状态
  26. ,Ordv_ClothingTime as 选衣时间
  27. , Ordv_FilmSelectionName as 选片师ID
  28. , dbo.fn_CheckUserIDGetUserName(Ordv_FilmSelectionName) as 选片师
  29. , Ordv_FilmSelectionStatus as 选片状态
  30. , Ordv_FilmSelectionTime as 选片时间
  31. , Ordv_EarlyRepairName as 初修师ID
  32. , dbo.fn_CheckUserIDGetUserName(Ordv_EarlyRepairName) as 初修师
  33. , Ordv_EarlyRepairStatus as 初修状态
  34. , Ordv_EarlyRepairTime as 初修时间
  35. , Ordv_RefinementName as 精修师ID
  36. , dbo.fn_CheckUserIDGetUserName(Ordv_RefinementName)as 精修师
  37. , Ordv_RefinementStatus as 精修状态
  38. , Ordv_RefinementTime as 精修时间
  39. ,Ordv_LookDesignName as 看设计师ID
  40. ,dbo.fn_CheckUserIDGetUserName(Ordv_LookDesignName) as 看设计师
  41. ,Ordv_LookDesignStatus as 看设计状态
  42. ,Ordv_LookDesignTime as 看设计时间
  43. ,Ordv_DesignerName as 设计师ID
  44. ,dbo.fn_CheckUserIDGetUserName(Ordv_DesignerName) as 设计师
  45. ,Ordv_DesignerStatus as 设计状态
  46. , Ordv_DesignerTime as 设计时间
  47. ,(case when (select Count(*) from (select [OPlist_PickupStatus] from [tb_ErpOrderProductList] where [OPlist_ViceNumber]=Ordv_ViceNumber and OPlist_Type = '2' and [OPlist_PickupStatus] = '0') as ta)>0 then '未取' else 'OK' end) AS 取件状态
  48. ,(select top 1 OPlist_PickupTime from tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type = '2' and OPlist_PickupTime is not null order by OPlist_PickupTime) AS 取件日期
  49. ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number)
  50. when 0 then (select count(id) as id from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number and (Ordpg_PhotographyStatus=0 or Ordpg_PhotographyStatus=2))
  51. when 1 then (select count(id) as id from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber and (Ordpg_PhotographyStatus=0 or Ordpg_PhotographyStatus=2))
  52. when 2 then (select count(id) as id from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number and (Ordpg_PhotographyStatus=0 or Ordpg_PhotographyStatus=2))
  53. else '' end) as 未拍个数
  54. from tb_ErpOrderDigital
  55. left join tb_ErpOrder on tb_ErpOrderDigital.Ordv_Number=tb_ErpOrder.Ord_Number
  56. GO